package zhou.jan22;

import java.sql.SQLException;

public class UserService {
	
	UserDao ud=new UserDao();
	User u1=new User();
	
	//用户注册：
	public boolean register(User u) throws SQLException{ 
		boolean flag=false;				
		u1=ud.getUserByName(u.getName());
		System.out.println("name2="+u.getPwd());					
		if((u1.getPwd()=="")&&ud.addUser(u)){       //不可以重名	
			flag=true;
		}			
		return flag;		
							
	}
	
	//用户登录：
	public boolean login(String username,String pwd) throws SQLException{  //第一个，往外抛
		boolean result=false;		
		u1=ud.getUserByName(username);
		if(pwd.equals(u1.getPwd())){
			result=true;
		}				
		return result;
	}
	
	//申请店主：
	public boolean openShop(User u) throws SQLException{
		boolean result=false;
		if(ud.getShopByName(u1)&&ud.addShop(u1)){										
			result=true;
				
		}else{
			return result;
		}				
		return result;
	}
	
	//添加商品：
	public boolean commodity(User u) throws SQLException{
		boolean result=false;
		if(ud.addCommodity(u1.getShop())){										
			result=true;
				
		}else{
			return result;
		}				
		return result;
	}

}
